/*====================================================*/
/* Copyright 2011 Justin Middleton                    */
/* License: Eclipse Public License v1.0,              */
/*          http://www.eclipse.org/legal/epl-v10.html */
/*====================================================*/

// for accounting requests
this.sixteenZeros = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]

function transposeDict(dict) {
    retDict = {}
    for (key in dict) {
        retDict[dict[key]] = key
    }
    return retDict
}

this.radiusAttrToAttrCode = {
	'framedipaddress'  :  8,    // the handset ip address
	'nasipaddress'     :  4,    // the GGSN's IP address
	'callingstationid' : 31,    // the MSISDN
	'calledstationid'  : 30,    // the APN
	'acctstatustype'   : 40     // START | STOP
}

this.radiusCodeToAttr = transposeDict(this.radiusAttrToAttrCode)


// we need these fore encoding. we only use a subset of course;
// the other two types are "text" and "time".
this.radiusAttrCodeToType = {
	40 : 'int',
	30 : 'string',
	31 : 'string',
	8 : 'address',
	4 : 'address'
}

this.radiusPacketTypeToCode = {
	'accountingrequest'   : 4,
	'accountingresponse'  : 5,
}

this.radiusCodeToPacketType = transposeDict(this.radiusPacketTypeToCode)


// packet field offsets
this.MAX_ATTR_SIZE = 255
this.MIN_ATTR_SIZE = 3

this.MAX_PACKET_SIZE = 4096
this.MIN_PACKET_SIZE = 20

this.OFFS_CODE       = 0
this.LEN_CODE        = 1

this.OFFS_IDENTIFIER = 1
this.LEN_IDENTIFIER  = 1

this.OFFS_LENGTH     = 2
this.LEN_LENGTH      = 2

this.OFFS_AUTHENTICATOR = 4
this.LEN_AUTHENTICATOR  = 16

this.OFFS_ATTRIBUTES    = 20

// attribute field offsets
this.OFFS_ATTR_TYPE     = 0
this.LEN_ATTR_TYPE      = 1

this.OFFS_ATTR_LENGTH   = 1
this.LEN_ATTR_LENGTH    = 1

this.OFFS_ATTR_VALUE    = 2
this.MAXLEN_ATTR_VALUE  = 253

this.ACCT_STATUS_START = 1
this.ACCT_STATUS_STOP  = 2
